home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / CommonSample / fileStuff.c next >
Encoding:
Text File  |  1995-06-08  |  2.4 KB  |  117 lines  |  [TEXT/MPCC]

  1. // Quickdraw 3D sample code
  2. //
  3. // Nick Thompson, AppleLink: DEVSUPPORT (devsupport@applelink.apple.com)
  4. //
  5. // ©1994-5 Apple Computer Inc., All Rights Reserved
  6.  
  7. #include "QD3D.h"
  8. #include "QD3DGroup.h"
  9. #include "QD3DIO.h"
  10. #include "QD3DStorage.h"
  11. #include "QD3DView.h"
  12. #include <StandardFile.h>
  13.  
  14. #include "FileStuff.h"
  15.  
  16.  
  17. void WriteGroupToFile( TQ3FileObject file, TQ3GroupObject theData, TQ3ViewObject theView)
  18. {
  19.     TQ3GroupPosition    gPos;
  20.     TQ3Object            object;
  21.     TQ3SharedObject        viewHints;
  22.     TQ3ViewStatus        fileStatus;
  23.     
  24.     if (Q3File_OpenWrite(file, kQ3FileModeNormal | kQ3FileModeText) == kQ3Success )
  25.     {
  26.     
  27.         Q3View_StartWriting(theView, file);
  28.  
  29.         if (theView == NULL)
  30.             viewHints = NULL;
  31.         else
  32.             viewHints = Q3ViewHints_New(theView);
  33.             
  34.         if (viewHints != NULL)
  35.         {
  36.             if (Q3Object_Submit(viewHints, theView) == kQ3Failure)
  37.             {
  38.                 Q3File_Cancel(file);
  39.                 return;
  40.             }
  41.         }
  42.             
  43.         do {
  44.             if (theData != NULL)
  45.             {
  46.                 TQ3Status status;
  47.                 
  48.                 status = Q3Group_GetFirstPosition(theData, &gPos);
  49.                 
  50.                 while (gPos != NULL && status == kQ3Success)
  51.                 {
  52.                     
  53.                     Q3Group_GetPositionObject(theData, gPos, &object);
  54.                     status = Q3Object_Submit(object, theView);
  55.                     Q3Object_Dispose(object);
  56.                     
  57.                     if (status != kQ3Failure)
  58.                     {
  59.                         Q3Group_GetNextPosition(theData, &gPos);
  60.                     }
  61.                 }
  62.             }
  63.     
  64.         } while ((fileStatus = Q3View_EndWriting(theView)) == kQ3ViewStatusRetraverse);
  65.             
  66.         if( Q3File_Close(file) == kQ3Failure ) {
  67.             return;
  68.         }
  69.     }
  70.     return ;
  71. }
  72.  
  73. Boolean WriteFile(TQ3GroupObject theData, TQ3ViewObject theView )
  74. {
  75.     Str255                thePrompt = "\pGimmie a file:", theName = "\pMetafile.3mf";
  76.     StandardFileReply    theReply;
  77.     OSErr                theResult;
  78.     long                length;
  79.     char                *bufPtr;
  80.     short                myRefNum ;
  81.     
  82.  
  83.     StandardPutFile( (ConstStr255Param) &thePrompt, (ConstStr255Param) &theName, &theReply);
  84.  
  85.     if (theReply.sfGood) {
  86.         if (!theReply.sfReplacing) {
  87.             if ((theResult = FSpCreate(&theReply.sfFile, '????', 'TEXT', theReply.sfScript)) != noErr) {
  88.                 SysBeep(1);
  89.                 return(false);
  90.             }
  91.         }
  92.     }
  93.     
  94.     if( theData ) {
  95.         TQ3StorageObject    storage;
  96.         TQ3FileObject        fd;
  97.         
  98.         storage = Q3FSSpecStorage_New( &theReply.sfFile );        
  99.         if (storage == NULL)
  100.             goto bail;
  101.         
  102.         fd = Q3File_New();
  103.         if (fd == nil)
  104.             goto bail;
  105.  
  106.         Q3File_SetStorage(fd, storage);
  107.         Q3Object_Dispose(storage);
  108.         
  109.         WriteGroupToFile( fd, theData, theView ) ;
  110.  
  111.         Q3Object_Dispose(fd);
  112.     }
  113.     return(noErr);
  114. bail:
  115.     return(fnOpnErr);
  116. }
  117.